<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-16 20:57:17
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-02-28 22:27:42
 * ------------------------------------------------ *
 * Ads                                          *
 * ------------------------------------------------ */
namespace Admin\Model;


class GoodsAppraisesModel extends CommonModel{

// 修改

	 public function editGoodsAppraises(){
	 	$id = (int)I("id",0);
		$m = M('goods_appraises');
		$data["goodsScore"] = I("goodsScore");
		$data["serviceScore"] = I("serviceScore");
		$data["timeScore"] = I("timeScore");
		$data["content"] = I("content");
		$data["isShow"] = (int)I("isShow",1);
		if($this->checkEmpty($data)){	
			$rs = $m->where("id=".(int)I('id'))->save($data);
			if(false !== $rs){
				return true;
			}
		}
		return false;
	 } 

// 获取指定对象

     public function get(){
	 	$id = (int)I('id');
		$sql = "select gp.*,o.orderNo,u.loginName,g.goodsName,g.goodsImg from __PREFIX__goods_appraises gp 
		         left join __PREFIX__goods g on gp.goodsId=g.goodsId
		         left join __PREFIX__orders o on gp.orderId=o.orderId 
		         left join __PREFIX__users u on u.userId=gp.userId 
		         where gp.id=".$id;
		$rs=$this->query($sql);
		return $rs[0];
	 }

// 分页列表

     public function getGoodsAppraises(){
     	$shopName = I('shopName');
     	$pageSize = (int)I('pageSize',0);
     	$goodsName = I('goodsName');
        //$m = M('goods_appraises');
	 	$sql = "select gp.*,g.goodsName,g.goodsImg,o.orderNo,u.loginName from __PREFIX__goods_appraises gp
	 	         left join __PREFIX__goods g on gp.goodsId=g.goodsId
		         left join __PREFIX__orders o on gp.orderId=o.orderId 
		         left join __PREFIX__users u on u.userId=gp.userId 
		         left join __PREFIX__shops p on p.shopId=gp.shopId 
	 	        where p.shopId=g.shopId and gp.goodsId=g.goodsId and o.orderId=gp.orderId ";
	 	if($shopName!='') $sql.=" and (p.shopName like '%".$shopName."%' or p.shopSn like '%".$shopName."%')";
	 	if($goodsName!='') $sql.=" and (g.goodsName like '%".$goodsName."%' or g.goodsSn like '%".$goodsName."%')";
	 	$sql.="  order by id desc";
		$rs = $this->PQ($sql,0,$pageSize);
		return $rs;
	 }
	  

// 删除

	 public function delGoodsAppraises(){
	 	$m = M('goods_appraises');
		$rs = $m->delete((int)I('id'));
		if($rs){
		   return true;
		}
		return false;
	 }
}